<?php
/**
 * Created by PhpStorm.
 * User: Adminstratot
 * Date: 2018/11/16
 * Time: 21:58
 */
namespace Admin\Controller;
use Think\Controller;
class UserinfoController extends Controller{
	//用户信息模板
    public function userinfo(){
        $this->verification();
        $userinfoModel=D('userinfo');
        $userinfoModel->uid=$uid=I('cookie.uid');
        if(IS_POST){
            if(!$userinfoModel->create()){
                $error=$userinfoModel->getError();
                echo "<script>alert('$error');location.href='javascript:history.go(-1)';</script>";
                exit;
            }
            cookie('name',I('post.name'));
            $userinfoModel->account=I('cookie.account');
            if($userinfoModel->where(array('uid'=>$uid))->save()){
                $url=U('Userinfo/userinfo');
                echo "<script>alert('保存成功。');location.href='$url';</script>";
            }

        }
        $infolist=$userinfoModel->where($uid)->select();
        $this->assign('infolist',$infolist);
        $this->display();
    }

    //验证是否没有登陆
    protected function verification(){
        $userModel=D('user');
        $userinfo=$userModel->where(array('account'=>cookie('account')))->find();
        if(!che() || !$userinfo){
            $url=U('User/login');
            echo "<script>alert('对不起，请您先登陆。');location.href='$url';</script>";
        }
    }
}
?>